package com.qf.controller;

import com.qf.entity.TbTeacher;
import com.qf.service.TeacherService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author:LGD
 * @Date:2023/7/17 16:34
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    @GetMapping("/find")
    public ResultMsg findAllTeacher(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "100   ")int limit, String teacherName,String teacherTeach){
        return teacherService.findAllTeacher(page,limit,teacherName.length()>0?teacherName:null,teacherTeach.length()>0?teacherTeach:null);
    }


    @GetMapping("/getInfo")
    public ResultMsg findTeacherById(int teacherId){
        return teacherService.getInfo(teacherId);
    }


    @PostMapping("/login")
    public ResultMsg teacherLogin(@RequestBody Map map, HttpServletRequest request){
        String name = (String) map.get("name");
        String password = (String) map.get("password");

        return teacherService.teacherLogin(name,password,request);
    }

    @GetMapping("/findName")
    public ResultMsg findOne(String name){
        return teacherService.findOne(name);
    }


    @PostMapping("/modify")
    public ResultMsg updateOrInster(@RequestBody TbTeacher tbTeacher){
        return teacherService.Modify(tbTeacher);
    }

    @PostMapping("/upload")
    public ResultMsg uploadImg(MultipartFile file){
        return teacherService.uploadImg(file);
    }

}